Java NIO: How to Avoid Overwriting an Existing File When Creating a New File Protect your file with a single enum.